using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace Avon
{
    /// <summary>
    /// a kategoriakData structura
    /// </summary>
    public struct KategoriakData
    {
        int m_KategoriaID;
        string m_KategoriaNev;
        /// <summary>
        /// a KatagoriakData konstruktora egy nevvel
        /// </summary>
        /// <param name="id">a kategoria id-ja</param>
        /// <param name="nev">a kategoria neve</param>
        public KategoriakData(string nev)
        {
            m_KategoriaID = 0;
            m_KategoriaNev = nev;
        }
        /// <summary>
        /// getterek es setterek
        /// </summary>
        public int KategoriaID
        {
            get { return m_KategoriaID; }
            set { m_KategoriaID = value; }
        }
        public string KategoriaNev
        {
            get { return m_KategoriaNev; }
            set { m_KategoriaNev = value; }
        }

    }
    /// <summary>
    /// szarmaztatom a KategoriaDAlt a DALbol
    /// </summary>
    public class KategoriaDAL : DAL
    {
        /// <summary>
        /// le kerem a kategoriak tabla listjata, az adataival
        /// </summary>
        /// <returns>a kategoria listat adja vissza</returns>
        public List<KategoriakData> GetKategoriaList()
        {
            string query = "SELECT KategoriaID,Nev" +
                            " FROM Kategoriak";
            string error = string.Empty;
            SqlDataReader rdr = ExecuteReader(query, ref error);
       
            List<KategoriakData> KategoriaList = new List<KategoriakData>();
            if (error == "OK")
            {
                while (rdr.Read())
                {
                    KategoriakData item = new KategoriakData();
                    item.KategoriaID = Convert.ToInt32(rdr[0]);
                    item.KategoriaNev = rdr[1].ToString();

                    KategoriaList.Add(item);
                }
            }
            CloseDataReader(rdr);
            return KategoriaList;
        }
       
      
    }
}
